home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7872 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.3 KB  |  98 lines

  1. Path: howland.reston.ans.net!psinntp!psinntp!psinntp!pipeline!not-for-mail
  2. From: johndill@nyc.pipeline.com (John Dillworth)
  3. Newsgroups: comp.lang.c
  4. Subject: Keep SetPixel in center
  5. Date: 29 Feb 1996 07:07:16 -0500
  6. Organization: The Pipeline
  7. Message-ID: <4h44tk$i24@pipe12.nyc.pipeline.com>
  8. NNTP-Posting-Host: pipe12.nyc.pipeline.com
  9. X-PipeUser: johndill
  10. X-PipeHub: nyc.pipeline.com
  11. X-PipeGCOS: (John Dillworth)
  12. X-Newsreader: The Pipeline v3.4.0
  13.  
  14. I have the following program.  I want to turn one pixel on and have it stay
  15. in the  center of the screen when ever I resize it.  I have managed to get
  16. the pixel on the screen.  How can I keep it in the canter?? 
  17.  
  18. #include <windows.h> 
  19.  
  20.  
  21. long FAR PASCAL _export WndProc (HWND, UINT, UINT, LONG) ; 
  22.  
  23. int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance, 
  24.                     LPSTR lpszCmdParam, int nCmdShow) 
  25.      { 
  26.      static char szAppName[] = "HelloWin" ; 
  27.      HWND        hwnd ; 
  28.      MSG         msg ; 
  29.      WNDCLASS    wndclass ; 
  30.  
  31.      if (!hPrevInstance) 
  32.           { 
  33.           wndclass.style         = CS_HREDRAW | CS_VREDRAW ; 
  34.           wndclass.lpfnWndProc   = WndProc ; 
  35.           wndclass.cbClsExtra    = 0 ; 
  36.           wndclass.cbWndExtra    = 0 ; 
  37.           wndclass.hInstance     = hInstance ; 
  38.           wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ; 
  39.           wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ; 
  40.           wndclass.hbrBackground = GetStockObject (BLACK_BRUSH) ; 
  41.           wndclass.lpszMenuName  = NULL ; 
  42.           wndclass.lpszClassName = szAppName ; 
  43.  
  44.           RegisterClass (&wndclass) ; 
  45.       } 
  46.  
  47.      hwnd = CreateWindow (szAppName,         // window class name 
  48.             "The Hello Program",     // window caption 
  49.                     WS_OVERLAPPEDWINDOW,     // window style 
  50.                     CW_USEDEFAULT,           // initial x position 
  51.                     CW_USEDEFAULT,           // initial y position 
  52.                     CW_USEDEFAULT,           // initial x size 
  53.                     CW_USEDEFAULT,           // initial y size 
  54.                     NULL,                    // parent window handle 
  55.                     NULL,                    // window menu handle 
  56.                     hInstance,               // program instance handle 
  57.             NULL) ;             // creation parameters 
  58.  
  59.      ShowWindow (hwnd, nCmdShow) ; 
  60.      UpdateWindow (hwnd) ; 
  61.  
  62.      while (GetMessage (&msg, NULL, 0, 0)) 
  63.           { 
  64.           TranslateMessage (&msg) ; 
  65.           DispatchMessage (&msg) ; 
  66.           } 
  67.      return msg.wParam ; 
  68.      } 
  69.  
  70. long FAR PASCAL _export WndProc (HWND hwnd, UINT message, UINT wParam, 
  71.                                                           LONG lParam) 
  72.      { 
  73.      HDC         hdc ; 
  74.      PAINTSTRUCT ps ; 
  75.      RECT     rect ; 
  76.  
  77.      switch (message) 
  78.           { 
  79.           case WM_PAINT: 
  80.            hdc = BeginPaint (hwnd, &ps) ; 
  81.                                                                        
  82.                GetClientRect (hwnd, &rect) ; 
  83.  
  84.           // DrawText (hdc, "Hello, Windows!", -1, &rect, 
  85.         //     DT_SINGLELINE | DT_CENTER | DT_VCENTER) ; 
  86.            SetPixel (hdc, 40,150, RGB(150, 0, 0)); 
  87.            EndPaint (hwnd, &ps) ;          
  88.         
  89.                return 0 ; 
  90.  
  91.           case WM_DESTROY: 
  92.                PostQuitMessage (0) ; 
  93.                return 0 ; 
  94.           } 
  95.  
  96.      return DefWindowProc (hwnd, message, wParam, lParam) ; 
  97.      } 
  98.